package com.ssm.constroller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ssm.model.Blog;
import com.ssm.model.User;
import com.ssm.model.UserInfo;
import com.ssm.service.IBlogService;
import com.ssm.service.IUserService;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TestConstroller {


   @Autowired
   IUserService service;

   @Autowired
    IBlogService blogService;



   private SqlSessionFactory sqlSessionFactory;


    @RequestMapping(value = "/findbyId")
    public String myMedel(Model model) {
//      User user = service.findUserById(1);
//        System.out.println();
        UserInfo user =  service.addUser(new UserInfo("aaaa","bbbb"));
//       model.addAttribute("message",user.getUsername());

        System.out.println(user.getId());
        return "index";
    }


    /**
     * 分页查询
     */
    @RequestMapping(value = "/pagelist")
    public  void test()
    {
        try {
            //使用分页查询 调用 pageHelper对象后 一定要紧跟查询语句否则拿不到数据
            Page page = PageHelper.startPage(1,2,true);
        
            List<Blog> list = blogService.PageListBlog();
            System.out.println(page.getPages());
            System.out.println(page.getTotal());




        } catch (Exception e) {
            e.printStackTrace();
        }



    }



}
